import { onlyIdFN } from '../utils/onlyId';
import { EventBus, EventBusClass } from '../utils/eventBus';
import { IMapMix, IListener } from '../../types/mapMix';
import { mapConst } from '../constants/mapConst';

export default class mapMix {
    /**
     * 发布事件
     */
    public $bus: EventBusClass = EventBus;
    /**
     * 取消广播数组
     */
    public eventBusList: IListener[] = [];
    /**
     * id
     */
    public id: string;
    /**
     * 全局关键对象
     */
    public mapConst = mapConst;

    constructor(data: IMapMix) {
        this.id = data.id || onlyIdFN();
    }
    /**
     * 清除监听事件
     */
    public clearEventBusFN() {
        this.eventBusList.forEach(element => {
            this.$bus.off(element.name, element.id);
        });
    }
}
